<form action="" class="form-horizontal" role="form">
  
  <div class="form-group">
    <label class="col-sm-2 control-label">商品名称</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" name="name" placeholder="请输入商品名称" datatype="*">
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">商品图片地址</label>
      <div class="col-sm-6">
        <input type="text" class="form-control margin-bottom" name="pic" id="pic" placeholder="请上传商品图片" datatype="*">
        <input type="file" name="file_upload" id="image_upload">
      </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">商品类目</label>
    <div class="col-sm-6">
      <div class="row">
        <div class="col-sm-4">
          <input type="text" class="form-control" disabled="true" id="class-control" placeholder="请选择商品类目">
          <input type="hidden" name="class_id" id="class-id">
        </div>
        <div class="col-sm-2">
          <span class="btn btn-info" id="class-select">选择类目</span>
        </div>
      </div>
      <ul id="class-content" class="ztree"></ul>
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">商品原价</label>
    <div class="col-sm-2">
      <input type="text" class="form-control" name="price_high" placeholder="输入价格信息">
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">商城价</label>
    <div class="col-sm-2">
      <input type="text" class="form-control" name="price" placeholder="输入价格信息">
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">价格属性</label>
    <div class="col-sm-2">
      <select name="price_attribute" class="form-control">{$priceAttributes}</select>
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">初始销量</label>
    <div class="col-sm-2">
      <input type="number" class="form-control" name="saled_base" placeholder="输入初始销量" min="1">
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">商品内容</label>
    <div class="col-sm-6">
      <script id="content" type="text/plain"></script>
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">运费</label>
    <div class="col-sm-6" id="is-shipping">
      {$is_shipping}
    </div>
  </div>
  
  <div class="form-group none" id="is-shipping-up">
    <label class="col-sm-2 control-label">运费价格</label>
    <div class="col-sm-6">
		  <label for="isApplyPostage_false">平邮：</label><input type="text" class="text text-short" maxlength="6" id="pyTF" name="shipping[0]" value="{$product['shipping'][0]?$product['shipping'][0]:5}"> 元
		  <label>快递：</label><input type="text" class="text text-short" maxlength="6" id="kdTF" name="shipping[1]" value="{$product['shipping'][1]?$product['shipping'][1]:'10'}"> 元
		  <label>EMS：</label><input type="text" class="text text-short" maxlength="6" id="emsTF" name="shipping[2]" value="{$product['shipping'][2]?$product['shipping'][2]:10}"> 元
    </div>
  </div>
  
  <div class="form-group">
    <label class="col-sm-2 control-label">商品状态</label>
    <div class="col-sm-6">
      {$status}
    </div>
  </div>
  
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-8">
      <a class="btn btn-default" onclick="javascript:history.go(-1)">返回上页</a>
      <a class="btn btn-default" onclick="self.location=document.referrer">返回上页并刷新</a>
      <input type="hidden" name="cat_id" value="{$cat_id}">
      <button type="submit" class="btn btn-primary submit" data-loading-txt="提交中，请稍后……" data-ajax-url="__CONTROLLER__/addPost">保存更改</button>
    </div>
  </div>
</form>

<!-- zTree -->
<style type="text/css">
  #class-control { position:relative; }
  #class-content { position:absolute; top:40px; left:15px; z-index:1000; display:none; background:#fff; border:1px solid #ccc; }
</style>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Style/Common/zTreeStyle/zTreeStyle.css">
<script src="__PUBLIC__/Style/Common/zTreeStyle/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">

  $("#class-select").on("click", function(){
    
    if ( $("#class-content").is(":hidden") ) {
      var _this = this;
      $.post("__CONTROLLER__/classPost", {}, function(data){
        var category = data.extra;
        selectClass( category );
        $(_this).html( "关闭" );
      });
      
    } else {
      $("#class-content").fadeOut(400);
      $(this).html( "选择类目" );
    }
    
  });
  
  //选择类目
  function selectClass ( category ) {
    var t = $("#class-content");
    var setting = {
      data: {
        simpleData: {
          enable:true,
          idKey: "id",
          pIdKey: "pid",
          rootPId: ""
        }
      },
      async: {
        autoParam:["id"],
        enable: true,
        url: "__CONTROLLER__/classPost",
        dataFilter: filter
      },
      callback: {
        onClick: function( event, treeId, treeNode ){
           $("#class-control").val(treeNode.name);
           $("#class-id").val(treeNode.id);
        } 
      }
    }
    var treeObj = $.fn.zTree.init( t, setting, category);
    $("#class-content").fadeIn(400);
  }
  
  function filter (treeId, treeNode, responseData) {
    return responseData.extra;
  }
  
  $(function(){
	  
	  var ready = $("#is-shipping input:checked").val();
	  if ( ready == 0 ) {
		  toggleShippingPrice( "show" )
	  } else {
		  toggleShippingPrice( "hide" )
	  }
	  
	  $("#is-shipping input").on("change", function() {
		  var v = this.value;
		  if( v == 0 ) {
			  toggleShippingPrice( "show" );
		  } else {
			  toggleShippingPrice( "hide" );
		  }
	  });
	  
	  function toggleShippingPrice( showHide ) {
		  showHide == "show" && $("#is-shipping-up").show();
		  showHide == "hide" && $("#is-shipping-up").hide();
	  };
  });
</script>
  
<!-- uploadify -->
<link rel="stylesheet" href="__PUBLIC__/Style/Common/uploadify/uploadify.css">
<script src="__PUBLIC__/Style/Common/uploadify/jquery.uploadify.min.js?{:rand(0,9999)}"></script>
<script type="text/javascript">
$(function() {
  $("#image_upload").uploadify({
    'multi'            :  false,
    'fileSizeLimit'    :  '200kb',
    'buttonText'       :  '选择图片',
    'fileTypeDesc'     :  'Image Files',
    'fileTypeExts'     :  '*.jpg; *.png',
    'swf'              :  '__PUBLIC__/Style/Common/uploadify/uploadify.swf',
    'uploader'         :  '__MODULE__/Upload/uploadOne',
    'onUploadSuccess'  :  function(data, res){
      var url = eval("(" + res + ")").extra.url;
      $("#pic").val( url );
    }
  });
});
</script>
<!-- ueditor -->
<link rel="stylesheet" href="/ue/themes/default/css/ueditor.min.css">
<script type="text/javascript" src="/ue/ueditor.config.js"></script>
<script type="text/javascript" src="/ue/ueditor.all.js"></script>
<script type="text/javascript">
  window.UEDITOR_HOME_URL = "/ue/";
    var editor = UE.getEditor("content",{
      initialFrameWidth: "100%",
      initialFrameHeight: 300,
      textarea: "content"
    });
    
</script>